import time

from selenium.webdriver.common.by import By

from BasePage.basepage import BasePage


class PageSureOrder(BasePage):
    def __init__(self, driver):
        super().__init__(driver)
        self.driver = driver
        # 点击购物车
        self.cart = (By.ID, "com.tpshop.malls:id/bottom_cart_img")
        # 立即购买
        self.buy_now = (By.ID, "com.tpshop.malls:id/buy_tv")
        # 提交订单
        self.submit_order = (By.ID, "com.tpshop.malls:id/submit_tv")
        # 立即支付 com.tpshop.malls:id/pay_btn
        self.pay_now = (By.ID, "com.tpshop.malls:id/pay_btn")
        # 支付密码输入框
        self.password = (By.ID, "com.tpshop.malls:id/pwd_et")
        # 确认支付
        self.confirm_pay_btn = (By.ID, "com.tpshop.malls:id/sure_tv")
#         下单成功
        self.sure_order_suc = (By.ID, "com.tpshop.malls:id/title_tv")

    def sure_order_by_card(self,password):
        self.click_element(self.cart)
        self.click_element(self.buy_now)
        self.click_element(self.submit_order)
        self.click_element(self.pay_now)
        time.sleep(2)
        self.base_clear_input(self.password, password)
        self.click_element(self.confirm_pay_btn)
        return self.get_element(self.sure_order_suc)
